<?php
	
	function runSQL($rsql) {
		global $_CONFIG;
		$connect = mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die ("Error: could not connect to database");
		$db = mysql_select_db($_CONFIG['dbname']);

		$result = mysql_query($rsql) or die(mysql_error());
		return $result;
		mysql_close($connect);
	}

	function countRec($fname, $tname) {
		$sql = "SELECT count($fname) FROM $tname ";
		$result = runSQL($sql);
		while ($row = mysql_fetch_array($result)) {
			return $row[0];
		}
	}
	
	function add($IdPalestra, $CognomeNome, $Categoria, $Peso) {
		$query = "INSERT INTO atleti (id_palestra, cognomenome, categoria, peso) 
			  VALUES (".$IdPalestra.", UPPER('".$CognomeNome."'), '".$Categoria."', ".$Peso.")";
			  
		$result = runSQL($query);
	} 
	
	function getPassword($Login, $Email) {
		$query = "SELECT username, password, nome, email FROM palestre WHERE username = '$Login' AND email = '$Email'";
		$result = runSQL($query);
		while ($row = mysql_fetch_array($result)) {
			return $row;
		}		
	}	
	
	function deleteAtleta($Id) {
		$query = "DELETE FROM atleti WHERE id = ".$Id;
		$result = runSQL($query);
	}	
	
?>